package com.ynby.yp.Controller;

import com.ynby.yp.Pojo.DruginforePojo;
import com.ynby.yp.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class IndexController {
    @Autowired
    IndexService indexService;


    @RequestMapping("indexPage.do")
    public String  indexPage(HttpServletRequest request){
        HttpSession session = request.getSession();
        if(session.getAttribute("flag")==null){
            return "page-login";
        }
        return "index";
    }

    @RequestMapping("query.do")
    @ResponseBody
    public List<DruginforePojo> query(DruginforePojo druginforePojo){
       return indexService.query(druginforePojo);
    }

    @RequestMapping("index.do")
    @ResponseBody
    public String add(DruginforePojo druginforePojo){

        if("".equals(druginforePojo.getDname())||druginforePojo.getDname()==null){
            return "请输入药品名称!!";
        }
      return   indexService.add(druginforePojo);
    }

}
